"""
this will act as the template for writing an authentication plugin
for the simple_auth service
"""
import os, sys
APPLICATION_INSTALL_DIR = os.environ.get('SIMPLEAUTH_INSTALL')
if not APPLICATION_INSTALL_DIR:
    raise EnvironmentError("Must Set SIMPLEAUTH_INSTALL in the environment!")

sys.path.append(os.path.join(APPLICATION_INSTALL_DIR, "lib%spython" % os.sep))

from simple_auth.config import DEFAULT_CONFIG_PATH, ConfigLoader


class TemplateAuthPlugin(object):
    def __init__(self, configName, configPath=None):
        if configPath is None:
            configPath = DEFAULT_CONFIG_PATH
        plugin_name = "plugin_" + configName
        try:
            self.config = ConfigLoader(configPath).load(plugin_name)
        except:
            try:
                possibleConfig = os.path.join(os.path.dirname(__file__), "conf")
                self.config = ConfigLoader(possibleConfig).load(server_name)
            except:
                raise
    
    def authenticate(self, username, password, **kwargs):
        """all full-coverage auth plugins must expose this method
           with this api"""
        raise NotImplementedError("The template class cannot authenticate!")
    
    def authorize(self, servicename, username, rolename, **kwargs):
        """all full-coverage auth plugins must expose this method
           with this api"""
        raise NotImplementedError("The template class cannot authorize!")